package com.smartrobot.smartrobot.circle.NewFriend;


import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;

import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;

import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import com.smartrobot.smartrobot.R;
import com.smartrobot.smartrobot.activity.ChatActivity1;
import com.smartrobot.smartrobot.activity.MainActivity;
import com.smartrobot.smartrobot.activity.New_friend_activity;
import com.smartrobot.smartrobot.pojo.getFriendListPojo;

/**
 * Created by yeluojun on 2015/1/20.
 */
public class Notify {


    public static int NEW_FRIEND_NUMBER = 0;


    private static int n_id = 993;

    public static void fRequestNotify2(Context context){
        int notifyID = 192;
        NotificationManager  mNotificationManager =
                (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.circle_icon)
                        .setContentTitle("朋友圈通知")
                        .setContentText("您收到了添加好友的申请");

        Intent resultIntent = new Intent(context, New_friend_activity.class);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

        stackBuilder.addParentStack(MainActivity.class);

        stackBuilder.addNextIntent(resultIntent);

        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                        0,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );
        mBuilder.setContentIntent(resultPendingIntent);

        //设置声音
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mBuilder.setSound(alarmSound);


        mNotificationManager.notify(notifyID, mBuilder.build());



    }

    public static void fRequestNotify(Context context){




        //通知您的理发师更新了日程
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(context.getApplicationInfo().icon)
                .setWhen(System.currentTimeMillis()).setAutoCancel(true);

        //设置状态栏提示
        mBuilder.setTicker("新消息提醒!");
        mBuilder.setContentTitle("朋友圈通知");
        mBuilder.setContentText("您收到了添加好友的申请");

        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mBuilder.setSound(alarmSound);


        //必须设置pendingintent，否则在2.3的机器上会有bug
        Intent intent = new Intent(context, New_friend_activity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 1 , intent, PendingIntent.FLAG_ONE_SHOT);
        mBuilder.setContentIntent(pendingIntent);

        Notification notification1 = mBuilder.build();
        notificationManager.notify(1992, notification1);

    }


    public static void fResponseNotify(Context context,getFriendListPojo pojo){
        //通知您的理发师更新了日程
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(context.getApplicationInfo().icon)
                .setWhen(System.currentTimeMillis()).setAutoCancel(true);

        //设置状态栏提示
        mBuilder.setTicker("新消息提醒!");
        mBuilder.setContentTitle("朋友圈通知");

        CharSequence contentText = "";
        if(pojo!=null){
            if(pojo.getName()!=null&&!pojo.getName().equals("")){
                contentText = pojo.getName()+"已经是您的好友啦，点击和TA聊天。";
            }else{
                contentText = pojo.getUserAccount()+"已经是您的好友啦，点击和TA聊天。";
            }
        }


        mBuilder.setContentText(contentText);
        //设置声音
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mBuilder.setSound(alarmSound);


        //必须设置pendingintent，否则在2.3的机器上会有bug
        Intent intent = new Intent(context, ChatActivity1.class);
        intent.putExtra("userId", pojo.getUserAccount());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 1 , intent, PendingIntent.FLAG_ONE_SHOT);
        mBuilder.setContentIntent(pendingIntent);

        Notification notification1 = mBuilder.build();
        notificationManager.notify(n_id, notification1);

    }



}
